package com.gmrz.uap.fidolog;

import com.gmrz.uap.cfg.SystemConst;
import com.gmrz.uap.common.ServiceSupport;
import com.gmrz.uap.model.FidoLog;
import com.gmrz.uap.util.Identities;
import com.jfinal.plugin.activerecord.Page;

import java.io.UnsupportedEncodingException;
import java.util.Map;

public class FidoLogService extends ServiceSupport {
    public static final FidoLogService me = new FidoLogService();

    /**
     * 根据页面传过来的条件进行分页查询
     *
     * @param fidoLog 业务日志信息
     * @param page    页号
     * @param rows    行数
     * @param sort    排序字段
     * @param order   升序/降序
     * @return　分页结果 Page<FidoLog>
     */
    public Page<FidoLog> findFidoLogListForPaginate(FidoLog fidoLog, int page, int rows, String sort, String order, Map<String, Object> condition) {
        return FidoLog.dao.findFidoLogListForPaginate(fidoLog, page, rows, sort, order, condition);
    }

    /**
     * 增加业务日志信息
     *
     * @param fidoLog 业务日志信息
     * @return true/false
     */
    public boolean save(FidoLog fidoLog) {
        fidoLog.set("fl_id", Identities.uuid2());
        return fidoLog.use(SystemConst.DB_FIDOLOG_DATASOURCE).save();
    }

    /**
     * 修改业务日志信息
     *
     * @param fidoLog 业务日志信息
     * @return true/false
     */
    public boolean update(FidoLog fidoLog) {
        return fidoLog.use(SystemConst.DB_FIDOLOG_DATASOURCE).update();
    }

    /**
     * 根据参数删除业务日志信息，ID可以是多个，中间使用逗号隔开
     *
     * @param ids ID集合
     * @return true/false
     */
    public boolean remove(String ids) {
        String[] idArr = ids.split(SystemConst._DEFAULT_SEPARATOR_COMMA);

        for (String id : idArr) {
            flag = FidoLog.dao.use(SystemConst.DB_FIDOLOG_DATASOURCE).deleteById(id);
        }
        return flag;
    }

    public String findFidoLogInfo(String flID, String infoType) throws UnsupportedEncodingException {
        return FidoLog.dao.findFidoLogInfo( flID, infoType);
    }
}
